package cn.support.neo.mvp.core.service.intercaptor;

import java.io.IOException;

import cn.support.neo.mvp.core.service.progress.ProgressListener;
import cn.support.neo.mvp.core.service.progress.ProgressResponseBody;
import okhttp3.Interceptor;
import okhttp3.Response;


/**
 * <b>Name:</b>xx页面<br>
 * <b>Author:</b> WK（wangkun@xjzhicheng.com)<br>
 * <b>Date:</b>  2017-03-23<br>
 * <b>Describe:</b><p> PLEASE TO FIXME...</p><br>
 * <p>代码说明：（重点）<br>
 * <ol>
 * <li> write something content..</li>
 * </ol>
 * </p>
 * <b>Version:</b>V1.0<br>
 * <b>Revision History:</b>
 * <ul>
 * v1.x<li>1.write something content..。<br>2.write something content..<br>3.write something content..<br></li>
 * </ul>
 * <br>
 */
public class ProgressInterceptor implements Interceptor {

    ProgressListener progressListener;

    public ProgressInterceptor(ProgressListener progressListener) {
        this.progressListener = progressListener;
    }

    @Override
    public Response intercept(Chain chain) throws IOException {
        //拦截
        Response originalResponse = chain.proceed(chain.request());
        //包装响应体并返回
        return originalResponse.newBuilder()
                .body(new ProgressResponseBody(originalResponse.body(), progressListener))
                .build();
    }
}
